<?php
session_start();
ob_start('ob_gzhandler');
include_once('config.php');

if(isset($_GET['language'])) {
	$_SESSION['language'] = $_GET['language'];
	header("location: ".$_SESSION['url']);
} else {
	if(!isset($_SESSION['language'])) {
		$_SESSION['language'] = 'en';
	}
}
$_SESSION['url'] = $_SERVER['REQUEST_URI'];
$language = $_SESSION['language'];

if($language=='en'){
	$home_page = 'home';
	include_once('language/en.php');
}else{
	$home_page = 'ホーム';
	include_once('language/jp.php');
}

include_once('blocks/menu.php');
if(@$_GET['danhmuc']){
	$dm = $_GET['danhmuc'];
	$dm = explode('/',$dm);
	$danhmuc = $dm[0];
	if($dm[1]=='') $page = 1; else $page = $dm[1];
	$menu_one = $tc->menu_one($danhmuc);
	$row_menu_one = mysql_fetch_array($menu_one);
	$idMenu = $row_menu_one['id'];
	$type = $row_menu_one['type_id'];
	
	if(!@$_GET['detail']){
		($row_menu_one['url_hinh']=='') ? $image='http://'.$domain.'/'.url_default_image : $image='http://'.$domain.'/'.url_danhmuc_image.$row_menu_one['url_hinh'];
		$url = 'http://'.$domain.'/'.$row_menu_one['url'];
		$seo = $tc->seo($domain,$row_menu_one['title'],$row_menu_one['metaDescription'],$row_menu_one['metaKeyword'],$image,$url);
		if($row_menu_one['url']=='golf-tournament/' || $row_menu_one['url']=='ゴルフトーナメント/') include_once('blocks/golftournament.php');
		if($row_menu_one['url']=='prizes/' || $row_menu_one['url']=='賞金/') include_once('blocks/prizes.php');
		if($row_menu_one['url']=='registration/' || $row_menu_one['url']=='登録者/') include_once('blocks/registration.php');
		if($row_menu_one['url']=='leader-board/' || $row_menu_one['url']=='リーダーボード/') include_once('blocks/leaderboard.php');
		if($row_menu_one['url']=='message-vietnam-works-golf-tournament/') include_once('blocks/message.php');
	}
}else{
	$menu_one = $tc->menu_one($home_page);
	$row_menu_one = mysql_fetch_array($menu_one);
	$image = 'http://'.$domain.'/'.url_default_image;
	$seo = $tc->seo($domain,$row_menu_one['title'],$row_menu_one['metaDescription'],$row_menu_one['metaKeyword'],$image,$row_menu_one['url']);
	include_once('blocks/home.php');
}

if(@$_GET['detail']){
	$dt = $_GET['detail'];
	$detail = $tc->detail($type,$dt);
	$row_detail = mysql_fetch_array($detail);
	($row_detail['url_hinh']!='') ? $image='http://'.$domain.'/'.url_detail_thumb_image.$row_detail['url_hinh'] : $image='http://'.$domain.'/'.url_default_image;
	$url = 'http://'.$domain.'/'.$row_menu_one['url'].$row_detail['name_rewrite'].'.html';
	$seo = $tc->seo($domain,$row_detail['name'],$row_detail['description'],$row_detail['metaKeyword'],$image,$url);
	include_once('blocks/detail_info.php');
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php echo $seo;
if($tc->get_user_browser()!='ie') echo '<link href="style.css" rel="stylesheet" type="text/css" />';
else echo '<link href="style_ie.css" rel="stylesheet" type="text/css" />';
?>
<script type="text/javascript" src="library/jquery.min.js"></script>
<script type="text/javascript" src="website.js"></script>
<noscript><meta http-equiv="refresh" content="2; URL=http://<?php echo $domain; ?>/thank.html"></noscript>
</head>

<body>
<div id="wrapper">
	<div id="header">
    	<div id="logo"><a href="" title="Vietnamworks"><img src="images/logo-vietnamworks.png" alt="logo vietnamworks" /></a></div>
    	<?php echo $view_menumain; ?>
    </div>
	<div id="content">
    	<?php
        echo $view_post;
		//include_once('blocks/message.php');
		?>
    </div>
	<?php echo $view_menufoo; ?>
</div>
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-103236-1']);
  _gaq.push(['_setDomainName', 'vietnamworks.com']);
  _gaq.push(['_trackPageview']);
 
  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
</script>
</body>
</html>
<?php mysql_close(); ?>